/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/08/07
*/
#ifndef __EDUI_SDL_SURFACE_H__
#define __EDUI_SDL_SURFACE_H__

#include "SDL.h"
#include "SDL_image.h"
#include "edui/interface/ISurface.h"
#include "edui_sdl/external/SDL_AniGif/SDL_anigif.h"

EDUI_NAMESPACE_BEGIN

class Surface : public ISurface
{
protected:
    Surface();
    virtual ~Surface();
public:
	static Surface* GetInterface();
	virtual void Release();
    static Surface* ToSurface(ISurface* surface);
#ifdef EDUI_TEST_NEW_DELETE
    static int m_newdeleteNum;
    static int _GetNewDeleteNum();
#endif
public:
    virtual bool Create(const char* file, const char* name = 0, int id = -1);
    virtual bool Create(void* mem, int size, const char* name, int id = -1, const char* type = 0);
    virtual bool CreateRGB(int width, int height, int depth,
                     Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask, const char* name, int id = -1);
    virtual bool CreateRGBFrom(void *pixels,
                         int width, int height, int depth, int pitch,
                         Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
                         Uint32 Amask, const char* name, int id = -1);
    
    // create use this function, you must Destroy and Release this surface.
	virtual bool Create(SDL_Surface* surface);

    virtual bool IsOK();
	virtual void Destroy();

    //surface number.
    virtual int GetNum();
    //for gif
    virtual Point GetOffset(int id);
    //for gif
    virtual int GetDelay(int id);

    virtual Size GetSize(int id = 0);
    virtual int Pitch(int id = 0);
    //read/write
    virtual void* Pixels(int id = 0);
    //read/write
    virtual void* UserData(int id = 0);

    virtual bool SetBlendMode(BlendMode mode, int id = 0);
	virtual BlendMode GetBlendMode(int id = 0);
    virtual bool SetColorMod(Uint8 r, Uint8 g, Uint8 b, int id = 0);
	virtual Color GetColorMod(int id = 0);
    virtual bool SetAlphaMod(Uint8 alpha, int id = 0);
	virtual Uint8 GetAlphaMod(int id = 0);
    //virtual bool SetColorKey();
    //virtual bool GetColorKey();

    virtual bool SetClip(const Rect *rect, int id = 0);
	virtual Rect GetClip(int id = 0);

    virtual bool Lock(int id = 0);
	virtual void Unlock(int id = 0);

public:
	SDL_Surface* GetSDLSurface(int id = 0) const;
protected:
    void _Add(SDL_Surface* surface);
protected:
    AG_Frame* m_frames;
    int m_num;
};

EDUI_NAMESPACE_END

#endif